﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class SystemManager_AddLinePhone : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            RECORDID.Text = "";
            String rID=Page.Request["ID"];
            if (rID != null && rID!="")
            {
                EntityOprHelper helper = new EntityOprHelper();
                T_ADDRESSLIST add = helper.GetEntityByWhere<T_ADDRESSLIST>(" where ID=" + rID + "");
                if (add != null)
                {
                    GT_ID.Text = add.NUMBER;
                    GT_TYPE.SelectedValue = add.TYPE;
                    GT_MODE.SelectedValue = add.MODE;
                    RECORDID.Text = add.ID.ToString();
                }
            }
            
        }
    }
    protected void Submit_Click(object sender, EventArgs e)
    {

        if (GT_ID.Text == "")
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('请输入帐号')", true);
            return;
        }
        EntityOprHelper helper = new EntityOprHelper();
        if (RECORDID.Text != "")
        {
            T_ADDRESSLIST address = new T_ADDRESSLIST();
            address.NUMBER = GT_ID.Text;
            address.TYPE = GT_TYPE.SelectedValue;
            address.MODE = GT_MODE.SelectedValue;
            address.ID = Convert.ToInt32(RECORDID.Text);

            bool b1 = helper.EditEntity<T_ADDRESSLIST>(address);
            if (b1)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('修改成功')", true);
                GT_ID.Text = "";
                RECORDID.Text = "";
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('修改失败')", true);
            }

            return;
        }


        
        T_ADDRESSLIST add=helper.GetEntityByWhere<T_ADDRESSLIST>(" where NUMBER='" + GT_ID.Text + "' and TYPE='" + GT_TYPE.SelectedValue + "'");

        if(add!=null)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('该帐号已经存在')", true);
            return;
        }

        T_ADDRESSLIST _address = new T_ADDRESSLIST();
        _address.NUMBER = GT_ID.Text;
        _address.TYPE = GT_TYPE.SelectedValue;
        _address.MODE = GT_MODE.SelectedValue;

       
        bool b=helper.AddEntity<T_ADDRESSLIST>(_address);
        if (b)
        {
                ScriptManager.RegisterClientScriptBlock(this,this.GetType(),"","alert('添加成功')",true);
                GT_ID.Text = "";
                
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('添加失败')", true);
        }

    }
}
